package fun.coding.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Combinations {

	
	public static void main(String[] args) {
		Combinations c = new Combinations();
		List<List<Integer>> r = c.combine(4, 2);
		
		for (List<Integer> l : r) {
			for (int i : l) {
				System.out.print(i + ",");
			}
			System.out.println();
		}
	}
	
	public List<List<Integer>> res = new ArrayList<List<Integer>>();
	
	public List<List<Integer>> combine(int n, int k) {
		List<Integer> l = new ArrayList<Integer>();
		helper(1, n, k, l);
		return res;
    }
	
	public void helper(int start, int n, int k, List<Integer> l) {
		if (k == 0) {
			res.add(new ArrayList<Integer>(l));
			return ;
		}
		
		for (int i = start; i <= n; i++) {
			l.add(i);
			helper(i + 1, n, k - 1, l);
			l.remove(l.size() - 1);
		}
		
	}

}
